#include "MineDesign3D/IShapeUI.hpp"
#include "MineDesign3D/BoxelManager.hpp"
#include "MineDesign3D/UIManager.hpp"
#include <AntTweakBar.h>
namespace MineDesign3D{
class SphereUI : public IShapeUI
{
public:
	virtual void Init()
	{
		if(TwGetBarByName("SphereConfig"))
		{
			TwDefine("SphereConfig visible=true");
		}
		else
		{
			TwBar* pSphereConfig = TwNewBar("SphereConfig");
			TwDefine("SphereConfig position='300 100' size='200 100'");

			struct Create
			{
				static void TW_CALL Do(void*)
				{
					g_pBoxelManager()->CreateShpere(size);
					g_pUIManager()->createShapeExit();
				}
				static void TW_CALL Canncel(void*)
				{
					g_pUIManager()->createShapeCanncel();
				}
			};

			TwAddVarRW(pSphereConfig,"Size",TW_TYPE_INT32,&size,"min=1");

			TwAddButton(pSphereConfig,"Create",Create::Do,0,"");
			TwAddButton(pSphereConfig,"Canncel",Create::Canncel,0,"");
		}
	}
	virtual void Fin()
	{
		TwDefine("SphereConfig visible=false");
	}
	static int size;
};
int SphereUI::size = 20;


class ConeUI : public IShapeUI
{
	virtual void Init()
	{
		if(TwGetBarByName("ConeConfig"))
		{
			TwDefine("ConeConfig visible=true");
		}
		else
		{
			TwBar* pConeConfig = TwNewBar("ConeConfig");
			TwDefine("ConeConfig position='300 100' size='200 120'");

			TwAddVarRW(pConeConfig,"Size",TW_TYPE_INT32,&size,"min=1");
			TwAddVarRW(pConeConfig,"Height",TW_TYPE_INT32,&height,"min=1");

			struct Create
			{
				static void TW_CALL Do(void*)
				{
					g_pBoxelManager()->CreateCone(size,height);
					g_pUIManager()->createShapeExit();
				}
				static void TW_CALL Canncel(void*)
				{
					g_pUIManager()->createShapeCanncel();
				}
			};

			TwAddButton(pConeConfig,"Create",Create::Do,0,"");
			TwAddButton(pConeConfig,"Canncel",Create::Canncel,0,"");
		}
	}
	virtual void Fin()
	{
		TwDefine("ConeConfig visible=false");
	}

	static int size;
	static int height;
};
int ConeUI::size = 31;
int ConeUI::height = 31;

IShapeUI::ptr CreateSphereUI()
{
	return IShapeUI::ptr(new SphereUI());
}
IShapeUI::ptr CreateConeUI()
{
	return IShapeUI::ptr(new ConeUI());
}

}//MineDesign3D